Skip to content

Improve volume matching on macOS and fix snapshot-based volume handling on macOS - #21

Merged
wknapik merged 18 commits into
mainfrom
wknapik-macos-volume-matching
Aug 17, 2026
Merged

Improve volume matching on macOS and fix snapshot-based volume handling on macOS#21
wknapik merged 18 commits into
mainfrom
wknapik-macos-volume-matching

Conversation

@wknapik

@wknapik wknapik commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

Snapshot-based volumes retain the origin volume name, so that's not a reliable way to match the AWS-level device to the macOS-level device.

Found a more reliable way to make the connection.

This PR also fixes handling of snapshot-based volumes on macOS.

@wknapik wknapik self-assigned this Aug 15, 2026
@wknapik
wknapik marked this pull request as ready for review August 15, 2026 04:28
@wknapik
wknapik requested a review from mihaiplesa as a code owner August 15, 2026 04:28
@mihaiplesa
mihaiplesa requested a balanced review from Copilot August 15, 2026 08:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the macOS (Darwin) volume-to-disk resolution and formatting/mounting flow to avoid relying on the EBS volume ID as a disk label, and updates documentation/sudoers guidance accordingly.

Changes:

  • Resolve macOS disks via system_profiler NVMe inventory and APFS container mapping.
  • Generate a random volume name for diskutil eraseDisk on macOS and adjust mounting to use device paths.
  • Update README disclaimer and tighten/adjust sudoers command aliases for the new behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
vol Reworks macOS disk discovery and changes format/mount behavior to use device nodes and random volume names.
README.md Updates disclaimer text and adapts sudoers regexes to the new diskutil invocation patterns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread vol
Comment thread vol Outdated
Comment thread vol
Comment thread vol
Comment thread vol
Comment thread vol Outdated
Comment thread README.md
Comment thread README.md
@wknapik
wknapik enabled auto-merge (squash) August 15, 2026 12:45
@wknapik
wknapik merged commit ee1aaa4 into main Aug 17, 2026
3 of 4 checks passed
@wknapik
wknapik deleted the wknapik-macos-volume-matching branch August 17, 2026 12:21
@mihaiplesa
mihaiplesa requested a balanced review from Copilot August 17, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Suppressed comments (2)

vol:297

  • Indexing with [0] on the filtered list will raise IndexError if no APFS container matches the NVMe physical store (or if expected keys/arrays are missing). Prefer locating a single match with next(..., None) and emitting a clear err(...) when not found so failures surface as actionable errors instead of an unhandled exception.
                        containers = run2json(['diskutil', 'apfs', 'list', '-plist'])['Containers']
                        device = [c['Volumes'][0]['DeviceIdentifier'] for c in containers
                            if c['PhysicalStores'][0]['DeviceIdentifier'] == nvme_matching['volumes'][0]['bsd_name']][0]

vol:285

  • system_profiler is typically slow, and get_disk() appears to be called in mount/format flows (and likely in polling loops such as wait_for_disk). Consider caching the parsed NVMe inventory for the duration of a mount operation (or for a short TTL) to avoid repeated expensive subprocess calls.
            nvme_all = json.loads(run(['system_profiler', '-json', 'SPNVMeDataType']).stdout)['SPNVMeDataType']
            nvme_items = sum((i['_items'] for i in nvme_all if i['_items']), [])
            nvme_matching = next((i for i in nvme_items if i['device_serial'] == volume_id.replace('-', '')), None)

Comment thread vol
if c['PhysicalStores'][0]['DeviceIdentifier'] == nvme_matching['volumes'][0]['bsd_name']][0]
return f'/dev/{device}'
else:
return f'/dev/{nvme_matching['bsd_name']}'
Comment thread README.md
```bash
sudo install -Tm440 /dev/stdin /etc/sudoers.d/99-vol <<-'EOF'
Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS vol-[0-9a-fA-F]+ /dev/disk[1-9][0-9]*$
Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS [a-zA-Z]+ /dev/disk[1-9][0-9]*$
Comment thread README.md
Comment on lines +305 to +307
Cmnd_Alias VOL_FORMAT = /usr/sbin/diskutil ^eraseDisk -noEFI APFS [a-zA-Z]+ /dev/disk[1-9][0-9]*$
Cmnd_Alias VOL_MOUNT = /usr/sbin/diskutil ^mount -mountPoint /mnt/point /dev/disk[1-9][0-9]*$
Cmnd_Alias VOL_UMOUNT = /usr/sbin/diskutil ^umount /mnt/point$, /usr/sbin/diskutil ^umount /Volumes/[a-zA-Z]+$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants